package me.jzn.alib.utils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Browser;
import android.provider.Settings;

import androidx.annotation.NonNull;

import me.jzn.alib.ALib;

//之所有有关intentUtil，而不直接jump，是因为有些需要query接口，而不都得跳转
public class SysIntentUtil {
    public static final Intent launchIntent(@NonNull Context context) {
        String pkgId = context.getApplicationInfo().packageName;
        return context.getPackageManager().getLaunchIntentForPackage(pkgId);
    }

    // 与appListIntentAll 相同
    public static final Intent appListIntent() {
        return new Intent(Settings.ACTION_APPLICATION_SETTINGS);
    }

    // 与appListIntent 相同
    public static final Intent appListIntentAll() {
        return new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
    }

    public static final Intent appListIntentInstalled() {
        return new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
    }

    public static final Intent appDetailIntent(String pkgName) {
        Uri packageURI = Uri.parse("package:" + pkgName);
        return new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
    }

    //uri 以http/https开头
    public static final Intent viewUri(Uri uri) {
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        //@see android.text.style.URLSpan
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, ALib.app().getPackageName());
        //intent.setClassName("com.UCMobile","com.uc.browser.InnerUCMobile");//打开UC浏览器
//        intent.setClassName("com.tencent.mtt","com.tencent.mtt.MainActivity");//打开QQ浏览器
        return intent;
    }

    /**
     * 开发者模式
     */
    public static final Intent developIntent() {
        return new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
    }
}
